const httpUrl = getApp().globalData.httpUrl;

const hideLoading = () =>{
  return new Promise((resolve, reject) => {
    wx.hideLoading({
      success: () =>{
        resolve(true); // 成功关闭loading，返回true
      },
      fail: () =>{
        reject(false); // 关闭loading失败，返回false
      }
    });
  });
};

Page({

    /**
     * 页面的初始数据
     */
    data: {
      userImage:"",
      userName:"",

    },

    toSetting(){
      wx.navigateTo({
        url: '/pages/setting/setting',
      })
    },

    gotoAddress(){
      wx.navigateTo({
        url: '/pages/address/address',
      })
    },
    hello(){
      wx.showToast({
        title: '敬请期待',
        icon:'none'
      })
    },
    gotoMyOrder(){
      wx.navigateTo({
        url: '/pages/myOrder/myOrder',
      })
    },

    init(){
      var that = this;
      wx.request({
        url: httpUrl + '/user',
        method:'GET',
        header:{
          'Shop_token':wx.getStorageSync('Shop_token')
        },
        success(res){
          if (res.data.code == 20041) {
            that.setData({
              userImage:res.data.data.userImage,
              userName:res.data.data.userName
            })
          }
          else if (res.data.code == 401) {
            console.log(res.data.msg);
            wx.removeStorageSync('Shop_token');
          }else{
            console.log(res.data.msg);
          }
        },
        fail(err){
          console.log(err);
        }
      })
    },
    
    onChange(event) {
      this.setData({
        activeNames: event.detail,
      });
    },

    center(){

        wx.navigateTo({
          url: '/pages/person/person?userName=' + this.data.userName + '&userImage=' + this.data.userImage,
        })
    },
    
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      var that = this;
      this.init();
    },

    /**
    * 生命周期函数--监听页面初次渲染完成
    */
    onReady() {
      wx.setNavigationBarTitle({
        title: "个人中心",
      });
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
      this.init();
      wx.stopPullDownRefresh();
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})